package com.demo2do.strawberry.handler.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;

public class StrawberryAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {

	/* (non-Javadoc)
	 * @see org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler#determineTargetUrl(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) {

		String beforeLoginUri = (String)request.getSession().getAttribute("beforeLoginUri");

		if(beforeLoginUri != null) {
			request.getSession().removeAttribute("beforeLoginUri");
			return beforeLoginUri;
		}

		return super.determineTargetUrl(request, response);
	}

}
